/*
 *  SoundEngine.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/5/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "SoundEngine.h"


SoundEngine * SoundEngine::INSTANCE = NULL;

SoundEngine * SoundEngine::getInstance() {	
	if(SoundEngine::INSTANCE == NULL) {
		SoundEngine::INSTANCE = new SoundEngine();	
	}
	
	return SoundEngine::INSTANCE;
}

SoundEngine::SoundEngine()
: music("../../sounds/music.m4a"), soundEnabled(false)
{
	sounds["Explosion"] = "../../sounds/effects/explosions/missile1.mp3";
	sounds["Projectile"] = "../../sounds/effects/missiles/missile1.wav";
	sounds["Impact"] = "../../sounds/effects/collisions/crapy.wav";
	sounds["PowerUp"] = "../../sounds/effects/powerUps/whooss.mp3";
}



void 
SoundEngine::toggleSound()
{
	if (soundEnabled) {
		music.stop();
	} else {
		//music.play();
	}

	
	soundEnabled = !soundEnabled;
}

void 
SoundEngine::play(const QString &name)
{
	if(!soundEnabled) return;
	
	if (!QSound::isAvailable()) {
		return;
	}
	
	QSound::play(sounds[name]);
}

void 
SoundEngine::addSound(const QString &name, const QString &path)
{
	 sounds[name] = path;
}

void 
SoundEngine::playMusic()
{
	if(!soundEnabled) return;
	music.play();
}

void
SoundEngine::stopMusic()
{
	music.stop();
}